#include "GameTimer.h"

GameTimer::GameTimer()
{
	QueryPerformanceFrequency(&frequency);
	startCount.QuadPart = 0;
	endCount.QuadPart = 0;

	_stopped = 0;
	_startTimeInMicroSec = 0;
	_endTimeInMicroSec = 0;
}

GameTimer::~GameTimer()
{
}

void GameTimer::start()
{
	_stopped = 0;
	QueryPerformanceCounter(&startCount);
}

void GameTimer::stop()
{
	_stopped = 1;

	QueryPerformanceCounter(&endCount);
}

double GameTimer::getElapsedTimeInMicroSec()
{
	if(!_stopped)
		QueryPerformanceCounter(&endCount);

	_startTimeInMicroSec = startCount.QuadPart * (1000000.0 / frequency.QuadPart);
	_endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart);
	return _endTimeInMicroSec - _startTimeInMicroSec;
}

double GameTimer::getStartTimeInMilliSec()
{
	return (startCount.QuadPart * (1000000.0 / frequency.QuadPart)) * 0.000001;
}

double GameTimer::getElapsedTimeInMilliSec()
{
	return this->getElapsedTimeInMicroSec() * 0.001;
}

double GameTimer::getElapsedTimeInSec()
{
	return this->getElapsedTimeInMicroSec() * 0.000001;
}

double GameTimer::getElapsedTime()
{
	return this->getElapsedTimeInSec();
}